import request from '@/utils/request'
import type { Swiper, SwiperQuery } from '@/types/swiper'
import type { ApiRes } from '@/types/data'

// 带条件分页查询轮播图列表
export const getBannerList = (params: SwiperQuery) => {
  // request第一个泛型，你写的是啥，将来 res.data 点出来的就是啥
  return request<ApiRes<{ total: number; items: Swiper[] }>>({
    url: 'banner/list',
    params
  })
}

interface SwiperForm {
  bannerid?: string
  alt: string
  flag: boolean
  img: string
  link: string
}
// 新增轮播图
export const addBanner = (data: SwiperForm) => {
  return request({
    url: 'banner/add',
    method: 'POST',
    data
  })
}

// 修改轮播图
export const updateBanner = (data: SwiperForm) => {
  return request({
    url: 'banner/update',
    method: 'POST',
    data
  })
}

// 删除轮播图
export const deleteBanner = (bannerid: string) => {
  return request({
    url: `banner/delete/${bannerid}`,
    method: 'DELETE'
  })
}
